<!DOCTYPE html>  
<html>
    <meta charset="utf-8" />  
    <title>队列</title>  
<body>
    <h2>队列</h2>
    <p>
        与栈相反，一种遵循先进先出 (FIFO / First In First Out) 原则的一组有序的项；
        队列在尾部添加新元素，并从头部移除元素。最新添加的元素必须排在队列的末尾
    </p>
</body>
<script>  
    class Queue{
        constructor(items){
            this.items = items||[]
        }

        enqueue(element){
            this.items.push(element)
        }

        dequeue(){
            return this.items.shift()
        }

        front(){
            return this.items[0]
        }

        clear(){
            this.items = []
        }

        get size(){
            return this.items.length
        }

        get isEmpty(){
            return !this.items.length
        }

        print() {
            console.log('print',this.items.toString())
        }

    }

    const queue = new Queue()
    console.log('isEmpty',queue.isEmpty) // true

    queue.enqueue('John')
    queue.enqueue('Jack')
    queue.enqueue('Camila')
    console.log('size',queue.size) // 3
    console.log('isEmpty',queue.isEmpty) // false
    queue.dequeue()
    queue.dequeue()
    queue.print() // 'Camila'
</script>  
</html>